package com.weiwu.weiwustore.controller;

import com.weiwu.weiwustore.entity.Role;
import com.weiwu.weiwustore.pojo.RestResponse;
import com.weiwu.weiwustore.pojo.RoleVo;
import com.weiwu.weiwustore.pojo.TaskListVo;
import com.weiwu.weiwustore.service.RoleService;
import com.weiwu.weiwustore.utils.CrudUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 权限相关接口
 */
@RestController
public class RoleController {
    @Autowired
    RoleService roleService;

    /**
     * 角色选择框数据
     * @return
     */
    @GetMapping("/role/getroleitem")
    public RestResponse getroleitem() {
        return new RestResponse(roleService.findRoleItem());
    }

    /**
     * 角色管理
     * @return 相关角色表格数据
     */
    @GetMapping("/role/getroles")
    public RestResponse getroles() {
        List<RoleVo> res = roleService.getroles();
        return new RestResponse(res, res.size(), 200);
    }

    @PostMapping("/role/updaterolemenus")
    public RestResponse updaterolemenus(@RequestBody Map<String, Object> map) {
        Integer result = roleService.updaterolemenus(map);
        return new RestResponse(null, 0, result == 1 ? 200 : 400);
    }
}
